import {Component, Input, OnInit} from '@angular/core';
import {EntityRef} from '../../entity/entity-ref';
import {DocService} from '../../service/doc.service';
import {deepCopy} from '../../utils/entity-utils';

@Component({
  selector: 'app-render-table-header-params',
  templateUrl: './render-table-header-params.component.html',
  styleUrls: ['./render-table-header-params.component.css']
})
export class RenderTableHeaderParamsComponent implements OnInit {
    params: EntityRef[];

    @Input()
    set apiParams(params: EntityRef[]) {
        this.params = deepCopy(params);
        this.initData();
    }

    constructor(private docService: DocService) {
    }

    ngOnInit() {

    }

    private initData() {
        this.params.forEach(header => {
            if (header.annotationParams && header.annotationParams.length > 2) {
                const params = JSON.parse(header.annotationParams);
                if (params['value']) {
                    header.name = params['value'];
                }
            }
        });
    }
}
